const app = getApp()
import {
  formatDate
} from "../../utils/util.js"
const INTERVAL = 10000;
Component({

  behaviors: [],

  properties: {
    myProperty: { // 属性名
      type: String,
      value: ''
    },
    myProperty2: String, // 简化的定义方式
  },

  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    pipei11: false,
    pipei21: false,
    jinsai: false,
    pipei_lahei: false,
    tanchuang19:false,
    xianhua:'',
    forbid_time:''
  }, // 私有数据，可用于模板渲染
  lifetimes: {
    ready() {

    },
    // 生命周期函数，可以为函数，或一个在 methods 段中定义的方法名
    attached: function () {
      let that = this
      this.timer = setInterval(function () {
        // that.z_kaihei1()
        // that.z_kaihei2()
        that.z_lahei()
        that.z_xianhua()
        // if(app.pipei == true){
        //   that.z_kaihei2()
        // }
        // 这里可以执行定时器需要执行的任务
      }, INTERVAL);
      setInterval(() => {
        that.setData({
          pipei21:getApp().pipei21,
          kaihei2:getApp().kaihei
        })
    }, 3000);
    },
    moved: function () {},
    detached: function () {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null; // 清除引用，便于垃圾回收
      }
      // this.z_kaihei2()
      this.z_lahei()
      this.z_xianhua()
    },
  },

  // 生命周期函数，可以为函数，或一个在 methods 段中定义的方法名
  attached: function () {}, // 此处 attached 的声明会被 lifetimes 字段中的声明覆盖
  ready: function () {},

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function () {
      this.z_yonghu()
      this.z_peizhi()
      // this.z_kaihei2()
    },
    hide: function () {},
    resize: function () {},
  },

  methods: {
    fuzhi1(e) {
      let _this = this
      wx.setClipboardData({
        data: e.currentTarget.dataset.tj_num,
        success(res) {
          wx.getClipboardData({
            success(res) {
              // console.log(res.data) // data
              wx.showToast({
                title: '复制成功',
                icon: 'success',
                duration: 2000
              })
              _this.z_close()
              wx.setStorageSync("pipei", 'false')
              wx.setStorageSync("baoming", '')
              let childobj = this.selectComponent('.my-component')
              childobj.setData({
                baoming5: true
              })
            }
          })
        }
      })
    },
    fuzhi3(e) {
      let _this = this
      _this.setData({
        pipei21: false
      })
      _this.z_kaihei3()
      let member_id = e.currentTarget.dataset.member_id
      let id = e.currentTarget.dataset.id
      wx.setStorageSync("memberid", member_id)
      let type = e.currentTarget.dataset.type
      wx.setStorageSync("kaiheitype", type)
      wx.navigateTo({
        url: '/packageA/pages/liao/liao?id=' + member_id,
      })
    },
    z_close() {
      this.setData({
        pipei11: false,
        tanchuang19:false
      })
    },
    z_close1() {
      this.setData({
        tanchuang19:false
      })
      this.z_xianhua1()
    },
    z_close2() {
      this.setData({
        pipei21:false
      })
      this.z_kaihei3()
    },
    z_lianjie(){
      this.setData({
        tanchuang19:false
      })
      this.z_xianhua1()
      wx.navigateTo({
        url: '/packageA/pages/liao/liao?id=' + this.data.xianhua.member_id,
      })
    },
    z_yonghu() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/member/myInfo',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          setTimeout(function(){
            _this.setData({
              forbid_time:res.data.data.forbid_time
            })
          },500)
          _this.setData({
            yonghu: res.data.data,
            tishi: res.data.msg
          })
          if (res.data.code == '1004') {
            _this.setData({
              jinsai: true
            })
          }
        }
      })
    },
    z_peizhi() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/config/configBase',
        method: 'GET',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          _this.setData({
            peizhi: res.data.data
          })
        }
      })
    },
    z_qingling() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/member/curLhClear',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          if (res.data.code == '1001') {
            _this.setData({
              pipei_lahei: false
            })
            wx.setStorageSync("pipei_lahei", 'false')
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    },
    z_kaihei1() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/compete/yqkhInfo',
        method: 'GET',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          if (res.data.data != '') {
            var flag = true
            if (res.data.data.type == wx.getStorageSync("kaiheitype") && res.data.data.member_id == wx.getStorageSync("memberid")) {
              flag = false
            }
            if (flag) {
              if (res.data.data.type == 2) {
                _this.setData({
                  pipei11: false,
                })
                _this.setData({
                  pipei11: true,
                  kaihei1: res.data.data
                })
              } else if (res.data.data.type == 1) {
                _this.setData({
                  pipei21: false,
                })
                _this.setData({
                  pipei21: true,
                  kaihei2: res.data.data
                })
              }
            }
          }
        }
      })
    },
    z_kaihei2() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/compete/khppSuccess',
        method: 'GET',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
            if(res.data.data != ''){
              _this.setData({
                kaihei2: res.data.data,
                pipei21: true
              })
            }
        }
      })
    },
    z_kaihei3() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
        "kh_id":app.kaihei.id
      }
      wx.request({
        url: app.apiurl + 'api/compete/upKhppSuccess',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
              _this.setData({
                pipei21: false
              })
              app.peizhi21 = false
              // _this.z_kaihei2()
        }
      })
    },

    z_lahei() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/member/curLhStatus',
        method: 'GET',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          if (res.data.data.lh_status == '1') {
            wx.setStorageSync("pipei_lahei", 'true')
            _this.setData({
              pipei_lahei: true
            })
          }
          if (wx.getStorageSync("pipei_lahei") == 'true') {
            _this.setData({
              pipei_lahei: true,
            })
          } else {
            _this.setData({
              pipei_lahei: false,
            })
          }
        }
      })
    },
    
    z_jujue(e) {
      let _this = this
      let type = e.currentTarget.dataset.type
      let member_id = e.currentTarget.dataset.member_id
      let params = {
        "token": wx.getStorageSync("user_token"),
        "id": _this.data.kaihei1.id,
        "type": '2'
      }
      wx.request({
        url: app.apiurl + 'api/compete/yqkhAgree',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          _this.z_close()
          wx.setStorageSync("memberid", member_id)
          wx.setStorageSync("kaiheitype", type)
        }
      })
    },
    z_tongyi(e) {
      let _this = this
      let type = e.currentTarget.dataset.type
      let member_id = e.currentTarget.dataset.member_id
      let params = {
        "token": wx.getStorageSync("user_token"),
        "id": _this.data.kaihei1.id,
        "type": '1'
      }
      wx.request({
        url: app.apiurl + 'api/compete/yqkhAgree',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          _this.z_close()
          wx.setStorageSync("memberid", member_id)
          wx.setStorageSync("kaiheitype", type)
        }
      })
    },
    z_xianhua() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token")
      }
      wx.request({
        url: app.apiurl + 'api/member/xhTan',
        method: 'GET',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          if (res.data.data != '') {
            _this.setData({
              xianhua: res.data.data,
              tanchuang19: true
            })
            // if(wx.getStorageSync("xianhua111") == ''){
            //   _this.setData({
            //     tanchuang19: true
            //   })
            //   wx.setStorageSync("xianhua111", 'true')
            // } else {
            //   _this.setData({
            //     tanchuang19: false
            //   })
            //   wx.setStorageSync("xianhua111", '')
            // }
          }
        }
      })
    },
    z_xianhua1() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
        "ds_id":_this.data.xianhua.id
      }
      wx.request({
        url: app.apiurl + 'api/member/upXhTan',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
            _this.setData({
              tanchuang19: false
            })
        }
      })
    },
    onMyButtonTap: function () {
      this.setData({
        // 更新属性和数据的方法与更新页面数据的方法类似
      })
    },
    // 内部方法建议以下划线开头
    _myPrivateMethod: function () {
      // 这里将 data.A[0].B 设为 'myPrivateData'
      this.setData({
        'A[0].B': 'myPrivateData'
      })
    },
    _propertyChange: function (newVal, oldVal) {

    }
  }

})